VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form FrmDiemTongHop 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Diem tong hop"
   ClientHeight    =   8085
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   12150
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8085
   ScaleWidth      =   12150
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame 
      Caption         =   "Thong tin chi tiet"
      Height          =   4335
      Left            =   4200
      TabIndex        =   0
      Top             =   360
      Width           =   7815
      Begin VB.TextBox txtGhiChu 
         Height          =   855
         Left            =   1560
         MultiLine       =   -1  'True
         TabIndex        =   17
         Top             =   2520
         Width           =   5895
      End
      Begin VB.CommandButton btnCapNhap 
         Caption         =   "Cap nhat"
         Height          =   375
         Left            =   6000
         TabIndex        =   16
         Top             =   3600
         Width           =   1215
      End
      Begin VB.TextBox txtDiemL2 
         Height          =   375
         Left            =   1560
         TabIndex        =   14
         Top             =   2040
         Width           =   2055
      End
      Begin VB.TextBox txtDiemL1 
         Height          =   375
         Left            =   1560
         TabIndex        =   12
         Top             =   1560
         Width           =   2055
      End
      Begin VB.TextBox txtTenMH 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   10
         Top             =   1080
         Width           =   4095
      End
      Begin VB.CommandButton btnChonMH 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   9
         Top             =   1080
         Width           =   375
      End
      Begin VB.CommandButton btnChonSV 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   8
         Top             =   600
         Width           =   375
      End
      Begin VB.TextBox txtTenSV 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   4
         Top             =   600
         Width           =   4095
      End
      Begin VB.CommandButton btnNhapMoi 
         Caption         =   "Nhap moi"
         Height          =   375
         Left            =   840
         TabIndex        =   3
         Top             =   3600
         Width           =   1215
      End
      Begin VB.CommandButton btnThem 
         Caption         =   "Them"
         Height          =   375
         Left            =   3360
         TabIndex        =   2
         Top             =   3600
         Width           =   1215
      End
      Begin VB.CommandButton btnXoa 
         Caption         =   "Xoa"
         Height          =   375
         Left            =   4680
         TabIndex        =   1
         Top             =   3600
         Width           =   1215
      End
      Begin VB.Label Label11 
         Caption         =   "Ghi chu"
         Height          =   255
         Left            =   360
         TabIndex        =   18
         Top             =   2640
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "Diem lan 2"
         Height          =   255
         Left            =   360
         TabIndex        =   15
         Top             =   2160
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "Diem lan 1"
         Height          =   255
         Left            =   360
         TabIndex        =   13
         Top             =   1680
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "Mon hoc"
         Height          =   255
         Left            =   360
         TabIndex        =   11
         Top             =   1200
         Width           =   975
      End
      Begin VB.Label lblStation 
         Caption         =   "Sinh vien"
         Height          =   255
         Left            =   360
         TabIndex        =   5
         Top             =   720
         Width           =   975
      End
   End
   Begin MSComctlLib.ListView lstvData 
      Height          =   7455
      Left            =   120
      TabIndex        =   6
      Top             =   480
      Width           =   3975
      _ExtentX        =   7011
      _ExtentY        =   13150
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.Label Label 
      Caption         =   "Danh sach diem sinh vien"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   7
      Top             =   120
      Width           =   4095
   End
End
Attribute VB_Name = "FrmDiemTongHop"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents formHSSV As FrmHSSV
Attribute formHSSV.VB_VarHelpID = -1
Private WithEvents formDanhMucMonHoc As FrmDanhMucMonHoc
Attribute formDanhMucMonHoc.VB_VarHelpID = -1
Private m_sMaSV As String
Private m_sMaMH As String
Private m_objDiemTongHop As clsDiemTongHop
Private m_ObjADORst  As ADODB.Recordset

Private Sub btnCapNhap_Click()
    Dim objDiemTongHopDto As clsDiemTongHop
    Dim errText As String
    
    If Not ValidateInput(errText) Then
        MsgBox errText, vbCritical, "ThongBao"
        Exit Sub
    End If
    
    Set m_objDiemTongHop = New clsDiemTongHop
    Set objDiemTongHopDto = New clsDiemTongHop
    
    objDiemTongHopDto.masv = Trim(m_sMaSV)
    objDiemTongHopDto.mamh = Trim(m_sMaMH)
    
    If IsNumeric(Trim(txtDiemL1.Text)) Then
        objDiemTongHopDto.DiemL1 = CInt(Trim(txtDiemL1.Text))
    Else
        objDiemTongHopDto.DiemL1 = 0
    End If
    
    If IsNumeric(Trim(txtDiemL2.Text)) Then
        objDiemTongHopDto.DiemL2 = CInt(Trim(txtDiemL2.Text))
    Else
        objDiemTongHopDto.DiemL2 = 0
    End If

    objDiemTongHopDto.Ghichu = Trim(txtGhiChu.Text)
    
    If m_objDiemTongHop.Update(objDiemTongHopDto) Then
        LoadData
        ResetFields
        MsgBox GetReport("CapNhat", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("CapNhat", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub btnChonMH_Click()
    Set formDanhMucMonHoc = New FrmDanhMucMonHoc
    formDanhMucMonHoc.EnableBtnChon = True
    formDanhMucMonHoc.Show 1, Me
End Sub

Private Sub btnChonSV_Click()
    Set formHSSV = New FrmHSSV
    formHSSV.EnableBtnChon = True
    formHSSV.Show 1, Me
End Sub

Private Sub ResetFields()
    m_sMaSV = ""
    txtTenSV.Text = ""
    m_sMaMH = ""
    txtTenMH.Text = ""
    txtDiemL1.Text = ""
    txtDiemL2.Text = ""
    txtGhiChu.Text = ""
End Sub

Private Sub btnNhapMoi_Click()
    ResetFields
End Sub

Private Sub btnThem_Click()
    Dim objDiemTongHopDto As clsDiemTongHop
    Dim errText As String
    
    If Not ValidateInput(errText) Then
        MsgBox errText, vbCritical, "ThongBao"
        Exit Sub
    End If
    
    Set m_objDiemTongHop = New clsDiemTongHop
    Set objDiemTongHopDto = New clsDiemTongHop
    
    objDiemTongHopDto.masv = Trim(m_sMaSV)
    objDiemTongHopDto.mamh = Trim(m_sMaMH)
    
    If IsNumeric(Trim(txtDiemL1.Text)) Then
        objDiemTongHopDto.DiemL1 = CInt(Trim(txtDiemL1.Text))
    Else
        objDiemTongHopDto.DiemL1 = 0
    End If
    
    If IsNumeric(Trim(txtDiemL2.Text)) Then
        objDiemTongHopDto.DiemL2 = CInt(Trim(txtDiemL2.Text))
    Else
        objDiemTongHopDto.DiemL2 = 0
    End If

    objDiemTongHopDto.Ghichu = Trim(txtGhiChu.Text)
    
    If m_objDiemTongHop.Insert(objDiemTongHopDto) Then
        LoadData
        ResetFields
        MsgBox GetReport("Them", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("Them", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub LoadData()
    Dim i As Integer
    Dim vLstViewItem As ListItem
    
    Set m_objDiemTongHop = New clsDiemTongHop
    Set m_ObjADORst = m_objDiemTongHop.SelectAll
    lstvData.ListItems.Clear
    i = 1
    
    Do While Not m_ObjADORst.EOF
        Set vLstViewItem = lstvData.ListItems.Add(i)
        vLstViewItem = m_ObjADORst!masv & "#" & m_ObjADORst!mamh
        vLstViewItem.SubItems(1) = m_ObjADORst!HoDem & " " & m_ObjADORst!tensv
        vLstViewItem.SubItems(2) = m_ObjADORst!TenMH
        m_ObjADORst.MoveNext
        i = i + 1
    Loop

End Sub

Private Sub btnXoa_Click()
    If Trim(m_sMaSV) = "" Or Trim(m_sMaMH) = "" Then Exit Sub
    
    Set m_objDiemTongHop = New clsDiemTongHop
     
    If MsgBox("Ban co chac chan muon xoa khong", vbInformation + vbOKCancel, "ThongBao") = vbOK Then
        If m_objDiemTongHop.Delete(Trim(m_sMaSV), Trim(m_sMaMH)) Then
            LoadData
            ResetFields
            MsgBox GetReport("Xoa", "ThanhCong"), vbInformation, "ThongBao"
        Else
            MsgBox GetReport("Xoa", "ThatBai"), vbCritical, "ThongBao"
        End If
    End If
End Sub

Private Sub Form_Load()
    Init
    LoadData
    Call ClearSelection(lstvData)
End Sub

Public Sub Init()
    lstvData.ColumnHeaders.Clear
    lstvData.ColumnHeaders.Add , , "MaSV#MaDD", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Sinh vien", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Mon hoc", lstvData.Width / 3
End Sub

Private Sub formHSSV_EVENTChooseItem(ByVal masv As String, ByVal tensv As String)
    m_sMaSV = masv
    txtTenSV.Text = tensv
End Sub

Private Sub formDanhMucMonHoc_EVENTChooseItem(ByVal madd As String, ByVal tendd As String)
    m_sMaMH = madd
    txtTenMH.Text = tendd
End Sub

Public Function ValidateInput(ByRef errText As String) As Boolean
    ValidateInput = True
    If Trim(txtTenSV.Text) = "" Then
        errText = "Ban chua chon sinh vien"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenMH.Text) = "" Then
        errText = "Ban chua chon mon hoc"
        ValidateInput = False
        Exit Function
    End If
End Function

Private Sub lstvData_ItemClick(ByVal item As MSComctlLib.ListItem)
    Dim msv_mpt() As String
    Dim msv As String
    Dim mpt As String
    
    msv_mpt = Split(item, "#")
    msv = msv_mpt(0)
    mpt = msv_mpt(1)
    Set m_ObjADORst = m_objDiemTongHop.SelectByID(msv, mpt)
    If Not m_ObjADORst Is Nothing Then
        m_sMaSV = m_ObjADORst!masv
        m_sMaMH = m_ObjADORst!mamh
        txtTenSV.Text = m_ObjADORst!tensv
        txtTenMH.Text = m_ObjADORst!TenMH
        txtDiemL1.Text = m_ObjADORst!DiemL1
        txtDiemL2.Text = m_ObjADORst!DiemL2
        txtGhiChu.Text = m_ObjADORst!Ghichu
    End If
End Sub


